package com.lc.hongtai.adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.lc.hongtai.MyApplication;
import com.lc.hongtai.R;
import com.lc.hongtai.activity.FindDetailActivity;
import com.lc.hongtai.conn.JsonEconomics;
import com.zcx.helper.bound.BoundViewHelper;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/4/21.
 */

public class Fourth_findAdapter extends RecyclerView.Adapter<Fourth_findAdapter.ViewHolder> {

    private Context context;
    private List<JsonEconomics.Info.Article> list;


    public Fourth_findAdapter(Context context, List<JsonEconomics.Info.Article> list) {
        this.context = context;
        this.list = list;

    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        @Bind(R.id.text_title)
        TextView tv_02;

        @Bind(R.id.iv_camera)
        SimpleDraweeView iv_camera;


        @Bind(R.id.text_content)
        TextView text_content;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }


    @Override
    public Fourth_findAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = BoundViewHelper.boundView(this, MyApplication.scaleScreenHelper.loadView((ViewGroup) LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_find, null)));

        Fourth_findAdapter.ViewHolder vh = new Fourth_findAdapter.ViewHolder(view);

        return vh;
    }

    @Override
    public void onBindViewHolder(Fourth_findAdapter.ViewHolder holder, final int position) {
        holder.tv_02.setText(list.get(position).title);
        holder.text_content.setText(list.get(position).art_info);
        holder.iv_camera.setImageURI(Uri.parse(list.get(position).art_img));
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("title", list.get(position).title);
                //http://vhost906.zihaistar.com/api/index/find_content?id=455
                intent.putExtra("url", "http://vhost906.zihaistar.com/api/index/find_content?id=" + list.get(position).id);
                intent.setClass(context, FindDetailActivity.class);
                context.startActivity(intent);
            }
        });
    }


    @Override
    public int getItemCount() {
        return list.size();
    }
}
